package com.yuzhihao.writejvm.constant;

import com.yuzhihao.writejvm.clazz.ClassInfo;
import com.yuzhihao.writejvm.format.PrintFormat;
import com.yuzhihao.writejvm.read.Parse;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.log4j.Log4j2;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Map;

/**
 *
 * The CONSTANT_Double_info Structure
 *
 * @author yzh
 * @since  2021年12月01日19:11:15
 */

@Data
@Log4j2
@EqualsAndHashCode(callSuper = true)
public class ConstantDoubleInfo extends ConstantPool{

    private int high_bytes_u4 = 4;

    private int high_bytes;

    private int low_bytes_u4 = 4;

    private int low_bytes;

    public ConstantDoubleInfo(Map<String,ConstantPool> pools) {
        super(pools);
        super.name = "Double";
    }

    @Override
    public void parse(DataInputStream dis, ClassInfo ci) {
        try {
            this.high_bytes = Parse.byteToInt(high_bytes_u4, dis);
            this.low_bytes = Parse.byteToInt(low_bytes_u4, dis);
        } catch (IOException e) {
            log.error(e.getMessage());
        }
    }

    @Override
    public String print() {
        //这里double不会计算。。。
        return PrintFormat.MEMPTY+String.valueOf(((long) high_bytes << 32) + low_bytes);
    }
}
